package com.enjoyor.soa.traffic.rest.efoms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.efoms.VideoGroupInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.VideoRelationInfoDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IVideoGroupInfoConsumeService;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IVideoRelationInfoConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/videoGroup" })
@Api("VideoGroupInfoController")
@CrossOrigin
public class VideoGroupInfoController {


	@Autowired
	private IVideoGroupInfoConsumeService videoGroupInfoConsumeService;

	/**
	 * 获取分组对象；
	 * 
	 * @param videoRelationId
	 * @return
	 */
	@GetMapping(value = { "getVideoGroupInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = VideoGroupInfoDto.class, code = 0, message = "")
	@ApiOperation("获取分组对象")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "videoGroupId", value = "分组编号", paramType = "query", dataType = "String") })
	public ResultPojo getVideoGroupInfo(
			@RequestParam(defaultValue = "", value = "videoGroupId", required = false) String videoGroupId,
			HttpServletRequest request) {
		return videoGroupInfoConsumeService.getVideoGroupInfo(videoGroupId);
	}

	/**
	 * 获取分组List
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getVideoGroupInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = VideoGroupInfoDto.class, code = 0, message = "")
	@ApiOperation("获取分组List")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "videoGroupId", value = "视频分组编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "parentCode", value = "父编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "key", value = "点位名称或编号", paramType = "query", dataType = "String"),
		@ApiImplicitParam(name = "devAreaCode", value = "区域编号", paramType = "query", dataType = "String")})
	public ResultPojo getVideoGroupInfoList(
			@RequestParam(defaultValue = "", value = "videoGroupId", required = false) String videoGroupId,
			@RequestParam(defaultValue = "", value = "parentCode", required = false) String parentCode,
			@RequestParam(defaultValue = "", value = "key", required = false) String key,
			@RequestParam(defaultValue = "", value = "devAreaCode", required = false) String devAreaCode,
			HttpServletRequest request) {
		return videoGroupInfoConsumeService.getVideoGroupInfoList(videoGroupId, parentCode, key,devAreaCode);
	}

	/**
	 * 获取分组Page
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getVideoGroupInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = VideoGroupInfoDto.class, code = 0, message = "")
	@ApiOperation("获取巡检记录Page")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "videoGroupId", value = "视频分组编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "parentCode", value = "父编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "key", value = "点位名称或编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "devAreaCode", value = "区域编号", paramType = "query", dataType = "String")})
	public ResultPojo getVideoGroupInfoPage(
			@RequestParam(defaultValue = "", value = "videoGroupId", required = false) String videoGroupId,
			@RequestParam(defaultValue = "", value = "parentCode", required = false) String parentCode,
			@RequestParam(defaultValue = "", value = "key", required = false) String key,
			@RequestParam(defaultValue = "", value = "devAreaCode", required = false) String devAreaCode,
			HttpServletRequest request, Page page) {
		return videoGroupInfoConsumeService.getVideoGroupInfoPage(videoGroupId, parentCode,key,devAreaCode,page);
	}

	/**
	 * 添加关联；
	 * @param videoRelationInfoDto
	 * @return
	 */
	@PostMapping(value = { "/insertVideoGroupInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加分组信息")
	public ResultPojo insertVideoGroupInfo(@RequestBody VideoGroupInfoDto videoGroupInfoDto, HttpServletRequest request) {
		return videoGroupInfoConsumeService.insertVideoGroupInfo(videoGroupInfoDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 修改分组；
	 * @param videoRelationInfoDto
	 * @return
	 */
	@PostMapping(value = { "/updateVideoGroupInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改分组信息")
	public ResultPojo updateVideoGroupInfo(@RequestBody VideoGroupInfoDto videoGroupInfoDto, HttpServletRequest request) {
		return videoGroupInfoConsumeService.updateVideoGroupInfo(videoGroupInfoDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 删除分组；
	 * @param VideoGroupId
	 * @param request
	 * @return
	 */
	@DeleteMapping(value = { "/deleteVideoGroupInfo" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除分组")
    @ApiImplicitParam(name = "VideoGroupId", value = "分组编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo deleteVideoGroupInfo(@RequestParam("VideoGroupId") String VideoGroupId, HttpServletRequest request) {
        return videoGroupInfoConsumeService.deleteVideoGroupInfo(VideoGroupId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }

}
